package com.sas.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.sas.dao.BaseDao;
import com.sas.dao.UserDao;
import com.sas.entity.User;


/**
 *	员工DAO实现类
 *  2017-11-20
 * @author 胡其安
 *
 */
@Repository("userDao")
public class UserDaoImpl extends BaseDao implements UserDao {
	
	
	/**
	 * 根据账户密码查询用户
	 * @param user
	 * @return
	 * @throws Exception
	 */
	@Override
	public User select_user_bypass(User user) throws Exception {
		User temp_user=getSqlSession().selectOne("user.select_user_by_name_pass", user);
		return temp_user;
	}

	/**
	 * 根据id查询员工
	 * @param user
	 * @return
	 * @throws Exception
	 */
	@Override
	public User select_user_byid(User user) throws Exception {
		User temp_user=getSqlSession().selectOne("select_user_by_id", user);
		return temp_user;
	}

	/**
	 * 根据登陆账户（编号）查询员工
	 * @param user
	 * @return
	 * @throws Exception
	 */
	@Override
	public User select_user_by_login_name(User user) throws Exception{
		User temp_user=getSqlSession().selectOne("select_user_by_login_name", user);
		return temp_user;
	}
	
	/**
	 * 分页查询
	 * @param user
	 * @return
	 * @throws Exception
	 */
	@Override
	public List<User> query_page_user_list(Map user) throws Exception {
		@SuppressWarnings("unchecked")
		
		List<User> users=getSqlSession().selectList("query_pageuser_Lists", user);
		//System.out.println("dao"+users);
		return users;
	}

	/**
	 * 根据员工id更新员工信息
	 * @param user
	 * @return
	 * @throws Exception
	 */
	@Override
	public int update_user_byid(User user) throws Exception {
		int result=getSqlSession().update("update_user_by_Id", user);
		return result;
	}

	/**
	 * 新增一个员工
	 * @param user
	 * @return
	 * @throws Exception
	 */
	@Override
	public int insert_user(User user) throws Exception {
		int id =getSqlSession().insert("insert_user", user);
		return id;
	}

	/**
	 * 统计查询员工人数
	 * @param map
	 * @return
	 * @throws Exception
	 */
	@Override
	public int selectCountUser(Map map) throws Exception {
		int count =(Integer) getSqlSession().selectOne("query_pageuser_count", map);
		return count;
	}

	/**
	 * 查询员工是否存在
	 * @param user
	 * @return
	 * @throws Exception
	 */
	@Override
	public boolean selectUserIsexists(User user) throws Exception {
		int count =(Integer)getSqlSession().selectOne("query_user_isexits", user);
		if(count>0){
			return true;
		}
		return false;
	}

	/**
	 * 建立员工部门关系，用于新增一个员工后的操作
	 * @param map
	 * @return
	 * @throws Exception
	 */
	@Override
	public boolean insert_dept_emp(HashMap map) throws Exception {
		getSqlSession().insert("insert_dept_emp", map);
		
		return true;
	}

	/**
	 * 根据id查询员工
	 * @param user_id
	 * @return
	 * @throws Exception
	 */
	@Override
	public int select_deptId_by_UserId(int user_id) throws Exception {
		int user_id1=(Integer) getSqlSession().selectOne("query_deptId_by_userId", user_id);
		return user_id1;
	}

	/**
	 * 根据id删除员工
	 * @param user
	 * @return
	 * @throws Exception
	 */
	@Override
	public boolean detele_user_by_userid(User user) throws Exception {
		int flag=getSqlSession().delete("delete_user_by_userid", user);
		return true;
	}

	/**
	 * 删除员工部门关系，用于删除原告信息之后的操作
	 * @param user
	 * @return
	 * @throws Exception
	 */
	@Override
	public boolean delete_dept_emp_by_userid(User user) throws Exception {
		getSqlSession().delete("delete_dept_emp_by_userid", user);
		return false;
	}

	/**
	 * 根据员工id查询领导
	 * @param user
	 * @return
	 * @throws Exception
	 */
	@Override
	public User selectManager_byuserId(User user) throws Exception {
		User user1=(User)getSqlSession().selectOne("query_managerId_by_userId", user);
		return user1;
	}

	
	

}
